package 代码记录.Bit48天集训;

import java.util.*;

/**答案已订正
 * 1.Fibonacci数列
 * 2.合法括号序列判断
 * @author zx
 * @create 2022-04-26 16:09
 */
public class day_07 {
    /**
     *
     * @自己做出来了
     */
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        boolean[] arr = new boolean[1000001];
        List<Integer> list = new ArrayList<>();
        int[] num = new int[1000001];
        num[0] = 0;
        num[1] = 1;
        for(int i = 2;i < num.length;i++){
            num[i] = num[i - 1] + num[i - 2];
            if(num[i] > 1000001){
                break;
            }
        }
        int count = 2;
        for(int i = 1;i < arr.length;i++){
            if(i == num[count]){
                count++;
                arr[i] = true;
            }
        }
        int res1 = 0;
        int res2 = 0;
        for(int i = N; i >= 1;i--){
            if(arr[i] == true){
                break;
            }else{
                res1++;
            }
        }
        for(int i = N;i <= 1000000;i++){
            if(arr[i] == true){
                break;
            }else{
                res2++;
            }
        }
        System.out.println(Math.min(res1,res2));
    }

    /**
     * @return 自己做出来了
     */
    public boolean chkParenthesis(String A, int n) {
        Deque<Character> stack = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if (A.charAt(i) == '(') {
                stack.push(A.charAt(i));
            } else if (A.charAt(i) == ')') {
                if (!stack.isEmpty()) {
                    if (stack.peek() == '(') {
                        stack.poll();
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
        return stack.isEmpty();
    }
}
